package com.qiuling.iot.service.impl;

import com.github.pagehelper.PageHelper;
import com.qiuling.iot.Exception.BusinessException;
import com.qiuling.iot.Exception.code.BaseResponseCode;
import com.qiuling.iot.entity.EquipmentData;
import com.qiuling.iot.mapper.EquipmentDataMapper;
import com.qiuling.iot.service.EquipmentDataService;
import com.qiuling.iot.utils.PageUtil;
import com.qiuling.iot.vo.req.EquipmentDataReqVO;
import com.qiuling.iot.vo.resp.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author：zhangqiang
 * @Description：
 * @Date：Created in 17:37 2020/3/12
 * @Modified By：
 */
@Service
public class EquipmentDataServiceImpl implements EquipmentDataService {

    @Autowired
    private EquipmentDataMapper equipmentDataMapper;

    @Override
    public PageVO<EquipmentData> pageInfo(EquipmentDataReqVO vo) {
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        return PageUtil.getPageVO(equipmentDataMapper.selectAll(vo));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteData(List<String> dataIds) {
        int i = equipmentDataMapper.batchDeletedData(dataIds);
        if(i == 0) {
            throw new BusinessException(BaseResponseCode.OPERATION_ERROR);
        }
    }
}
